import { View, Image, Text, Button } from "@tarojs/components"

import JoinNoticeDialog from '@/components/joinNoticeDialog/joinNoticeDialog'

import EmptyImg from '@/assets/images/empty.png'
import { forwardRef, useEffect, useState } from "react"
import { USER_PROFILE_STATUS } from "@/typing"
import { handleCleanStore, handleGoKnow, toPage } from "@/common/util"
import { PAGE_PATH, PAGE_TYPE } from "@/common/config"
import Taro from "@tarojs/taro"
import useProfileInfoAction from "@/hooks/useProfileInfoAction"
// import { useStore } from '@/store';

import './pendingAndUnknown.scss'
import { handleIndexInit } from "@/common/service"

interface IPendingAndUnknown {
    noticeShow: boolean
    userProfileStatus: USER_PROFILE_STATUS;
    handlePopStatus: (status) => void;
}
const PendingAndUnknown: React.FC<IPendingAndUnknown> = forwardRef(({ userProfileStatus, noticeShow, handlePopStatus }, ref) => {
    // const [noticeShow, setNoticeShow] = useState(false)
    // const handlePopStatusAction = (popStatus) => {
    //     setNoticeShow(popStatus)
    // }
    //   const { regionStore } = useStore()
    const [showTip, setShowTip] = useState(false)
    let pageTimeOut;
    const { handleInitStoreProfileInfo } = useProfileInfoAction()
    const handleGoDetail = () => {
        if (userProfileStatus === USER_PROFILE_STATUS.pending) {
            Taro.navigateTo({
                url: `${PAGE_PATH.EXAMINE_PROCESS}?pageEntry=1`
            })
        } else if (userProfileStatus === USER_PROFILE_STATUS.unknown) {
            handlePopStatus(true)
            // handleCleanStore()
        }

    }
    const handleGoSettled = () => {
        handleCleanStore()
        // regionStore.handleInitRegionList()
        // jobStore.handleInitJobList();
        // serviceStore.handleInitServiceTypeList()
        // handlePopStatus(false)
        // toPage(PAGE_TYPE.USER_JOIN_INFO)
        handleInitStoreProfileInfo();
        pageTimeOut = setTimeout(() => {
            toPage(PAGE_TYPE.USER_JOIN_INFO)
        }, 300);
    }
    const handleIndexInitAjax = async () => {
        const res = await handleIndexInit() as any;
        console.log(res)
        if (res.data.code === 1) {
            const { data } = res.data;
            if (data.is_register === 0) {
                setShowTip(true)
            }
        }

    }

    useEffect(() => {
        handleIndexInitAjax()
        return () => {
            clearTimeout(pageTimeOut)
        };

    }, []);

    // useEffect(() => {

    //    try {
    //     if(noticeShow){
    //         Taro.hideTabBar()
    //       }else{
    //         Taro.showTabBar()
    //       }
    //    } catch (error) {

    //    }
    // }, [noticeShow]);
    return (
        <>
            <View className=" box-border flex items-center justify-center h-100vh">
                <View className="flex flex-col items-center">
                    <Image src={EmptyImg} className="w-190px h-202px"></Image>
                    <View onClick={handleGoDetail} className="mt-114px w-496px h-108px bg-#8232E8 flex items-center justify-center text-#fff text-36px">
                        {userProfileStatus === USER_PROFILE_STATUS.pending ? '信息审核中' : '入驻后可接单'}
                    </View>
                    <View className="text-#242424 mt-64px text-29px" onClick={handleGoKnow}>了解如何推广及接单 》</View>
                   {showTip&& <View className="mt-60px px-32px pb-32px leading-46px">
                        <View className="font-semibold text-28px">你好， 此服务仅限邀请入驻的聊见博主才能使用</View>
                        <View className="relative">
                            <Text className="text-#666">请先完成入驻，管理员审核通过后才能使用此小程序功能。
                                如有问题请</Text><Text className="text-blue-400" >「联系客服」</Text>
                            <Button className="service-button bg-transparent  mx-0 px-0 border-transparent w-full h-100px absolute left-0 top-0 bottom-0 right-0" openType="contact" sessionFrom='sessionFrom'></Button>
                        </View>
                    </View>}
                </View>
            </View>
            <JoinNoticeDialog noticeShow={noticeShow} handlePopStatus={handlePopStatus} handleGoAction={handleGoSettled}></JoinNoticeDialog>


        </>
    )
})

export default PendingAndUnknown;